var readline = require('readline-sync')
readline.setDefaultOptions({ prompt: '' })
var readline = readline.prompt
let [n, m] = readline().split(' ');
let arr = readline().split(' ').map(item => Number(item)), len = arr.length;
let [one, two, three, four] = readline().split(' ').map(item => Number(item));
let res = 0;
backtracking(0, one, two, three, four, 0);
console.log(res + arr[len - 1])
function backtracking (start, one, two, three, four, cursum) {
  if (start == len - 1) {
    res = Math.max(res, cursum);
  }
  if (one > 0) {
    backtracking(start + 1, one - 1, two, three, four, cursum + arr[start])
  }
  if (two > 0) {
    backtracking(start + 2, one, two - 1, three, four, cursum + arr[start])
  }
  if (three > 0) {
    backtracking(start + 3, one, two, three - 1, four, cursum + arr[start])
  }
  if (four > 0) {
    backtracking(start + 4, one, two, three, four - 1, cursum + arr[start])
  }
}
